<?php
session_start();
ob_start();
define('INDEX',true);
require("../../_config/config.php");
require("../../_config/db_connection.php");
require("../../common/functions_mysql.php");
require("../../common/functions_common.php");
require("../../common/init.php"); // Initial file
require("../../common/lang_".$cfg['admin_language'].".php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><?php echo $cfg['admin_header']?></title>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $cfg['default_charset']; ?>">
<script language="javascript" src="chart.js"></script>
<style>
BODY
{
	background-color:#FFFFFF;
	margin: 0px 0px 0px 0px;
	font-family: Tahoma, Arial;
	font-size:11px;
}
TD { font-size:11px; font-family: Tahoma, Arial;}
DIV { font-size:11px; font-family: Tahoma, Arial;}
</style>
</head>
<body>
<?php
$month_visitor = $DB->fetch_array($DB->query('SELECT SUM(visitors) AS total_visitors FROM '.$tbl["visitor"].' WHERE year="'.@$_GET['year'].'" AND month="'.$_GET['month'].'"'));
$month_visitors = $month_visitor['total_visitors'];

## LOAD CHART VISIT PER DAY
// Delete old xml
//unlink('xml/visit_per_day.xml');
// Get visitors per day
for($y=1;$y<=31;$y++) 
{ 
	$date[$y] = $DB->fetch_array($DB->query('SELECT * FROM '.$tbl["visitor"].' WHERE date="'.$y.'" AND month="'.@$_GET['month'].'" AND year="'.@$_GET['year'].'"'));
}
// Create new xml
$xml_vpd = "<?xml version='1.0' encoding='UTF-8' ?>";
$xml_vpd .= "<graph caption='".$lang_month[$_GET['month']].": ".$month_visitors." visitors' canvasBorderColor='666666' animation='1' numdivlines='9' showNames='1' showValues='0' chartLeftMargin='5' chartRightMargin='5'  chartTopMargin='0' showLegend='0' showAnchors='1' rotateNames='0' formatNumberScale='0' decimalPrecision='0' formatNumber='1' yAxisName='' divLineColor='CCCCCC'  showAlternateHGridColor='1'>";
for($x=1;$x<=31;$x++) 
{
	$xml_vpd .= "<set name='".(($x>9)?$x:'0'.$x)."' hoverText='".$lang_day[date ("w", mktime(0,0,0,$_GET['month'],$x,$_GET['year']))]."' value='".(($date[$x]['visitors'])?intval($date[$x]['visitors']):0)."' color='006699'/>";
}
$xml_vpd .= "</graph>";
$vpd_file_url = "xml/visit_per_day.xml";
$fp = fopen($vpd_file_url,'w');
$write = fwrite($fp,$xml_vpd);
	
if($month_visitors)
{
echo '<div id="visit_per_day">
					Your browser is not installed Flash Player. Please install flash player to view.
		</div>
		<script type="text/javascript">
				var chart_day = new JcasChart("swf/col2d.swf", "cd", "600", "300");
				chart_day.setDataURL("xml/visit_per_day.xml?SID='.session_id().'&rand='.rand(111111,99999).'");
				chart_day.render("visit_per_day");
		</script>';
}
else echo '<br/><div align=center>'.message(sprintf($lang['no_month_data'],get('month')),'info').'</center>';
?>

</body>
</html>
<?php
require('../../common/debug.inc.php');
$DB->close;
ob_end_flush();
?>